package com.ja.openchat.ui.chat.redpacket;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ja.openchat.R;
import com.ja.openchat.views.UserAvatarView;
import com.zy.openchat.core.model.redpacket.RedPacketPickUser;
import com.zy.openchat.core.model.user.UserInfo;
import com.zy.openchat.util.TimeConvertUtils;

import org.jetbrains.annotations.NotNull;

public class RedPacketDetailAdapter extends BaseQuickAdapter<RedPacketPickUser, BaseViewHolder> {

    public RedPacketDetailAdapter() {
        super(R.layout.item_red_packet_detail);
    }
    private long bestUserId = -1;

    public void setBestUserId(long userId){
        bestUserId = userId;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, RedPacketPickUser redPacketPickUser) {
        UserInfo userInfo = UserInfo.getUserInfo(redPacketPickUser.userId);
        UserAvatarView userAvatarView = baseViewHolder.getView(R.id.portraitView);
        if(userInfo!=null){
            userAvatarView.showUser(userInfo);
            baseViewHolder.setText(R.id.user_name,userInfo.displayName());
        }
        baseViewHolder.setText(R.id.get_red_time, TimeConvertUtils.formatDate8(redPacketPickUser.gotAt*1000));
        baseViewHolder.setText(R.id.get_red_num,String.format("%s元",redPacketPickUser.price));
        baseViewHolder.setGone(R.id.red_most_tag,redPacketPickUser.userId != bestUserId);
    }
}
